package one.chapter_2;

import edu.princeton.cs.algs4.StdOut;

public abstract class AbstractSort {

    protected abstract void sort(Comparable[] a);

    protected boolean less(Comparable v,Comparable w){
        return v.compareTo(w)<0;
    }

    protected void exch(Comparable [] a,int i,int j){
        Comparable temp=a[i];
        a[i]=a[j];
        a[j]=temp;
    }

    protected void show(Comparable [] a){
        for (int i=0;i<a.length;i++){
            StdOut.printf(a[i]+" ");
        }
        StdOut.println();
    }

    protected boolean isSorted(Comparable [] a){
        for (int i=1;i<a.length;i++){
            if (less(a[i],a[i-1])){
                return false;
            }
        }
        return true;
    }




}
